/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Dec 31, 2009
 * Time: 11:05:33 AM
 * To change this template use File | Settings | File Templates.
 */
import java.util.Iterator;
import java.util.List;
import org.jdom.Element;

// Referenced classes of package dk.brics.dsd:
//            Boolexp, Schema, Context

class AndBoolexp extends Boolexp
{

    AndBoolexp(Element element, Schema schema)
    {
        contents = parseList(element, schema);
    }

    byte evaluate(Context context)
    {
        byte byte0 = 1;
        Iterator iterator = contents.iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            Boolexp boolexp = (Boolexp)iterator.next();
            byte byte1 = boolexp.evaluate(context);
            if(byte1 == 2)
                return 2;
            if(byte1 == 4 || byte1 == 3 && byte0 == 3)
                byte0 = 4;
            else
            if(byte1 == 3 && byte0 == 1)
                byte0 = 3;
        } while(true);
        return byte0;
    }

    boolean isMentioned(Context context)
    {
        for(Iterator iterator = contents.iterator(); iterator.hasNext();)
        {
            Boolexp boolexp = (Boolexp)iterator.next();
            if(boolexp.isMentioned(context))
                return true;
        }

        return false;
    }

    Element toXML(Context context)
    {
        Element element = new Element("and", "http://www.brics.dk/DSD/2.0");
        for(Iterator iterator = contents.iterator(); iterator.hasNext(); element.addContent(((Boolexp)iterator.next()).toXML(context)));
        return element;
    }

    boolean containsThis(Context context)
    {
        for(Iterator iterator = contents.iterator(); iterator.hasNext();)
            if(((Boolexp)iterator.next()).containsThis(context))
                return true;

        return false;
    }

    List contents;
}
